home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
memory
/
pmdkt110
/
heap.dif
< prev
next >
Wrap
Text File
|
1994-11-14
|
5KB
|
234 lines
*** c:\bp\rtl\sys\heap.asm Wed Oct 28 07:00:00 1992
--- heap.asm Sat Oct 22 16:58:30 1994
***************
*** 20,27 ****
EXTRN FreeList:DWORD,HeapError:DWORD
! ; Local variables
AllocSize DW ?
DATA ENDS
--- 20,36 ----
EXTRN FreeList:DWORD,HeapError:DWORD
! ;;MemCheck externals
+ EXTRN CheckMEM:BYTE,StoreAlloc:DWORD,FreeAlloc:DWORD
+
+
+ ;; Local variables
+
AllocSize DW ?
+ ;; Memchecker variable
+
+ MemSize DW ?
+
DATA ENDS
***************
*** 39,42 ****
--- 48,52 ----
PUBLIC GetFreMem,GetFreMax,NewMemory,DisMemory
+
; New and GetMem standard procedures
***************
*** 161,167 ****
NewMemory:
OR AX,AX
! JE @@9
! MOV AllocSize,AX
@@1: CALL PointerSize
MOV DI,OFFSET DS:FreeList
--- 171,200 ----
NewMemory:
+ ;; memchecker code
+ mov [MemSize],ax
+
OR AX,AX
!
! ;; this jump was too far, so changed by memchecker
! ;; JE @@9
! jne @@m0
! jmp @@9
!
! ;; memchecker code
! ;; add 8 or 16 bytes to allocated memory for overflow checking
!
! @@m0: cmp CheckMem,0 ; is MemCheck code enabled?
! je @@m1
! cmp ax,65512 ; 65536-8-16
! ja @@CheckUpperArea
! add ax,16
! jmp short @@m1
! @@CheckUpperArea:
! cmp ax,65520 ; 65536-8-8
! ja @@m1
! add ax,8
!
! @@m1:
! MOV AllocSize,AX
@@1: CALL PointerSize
MOV DI,OFFSET DS:FreeList
***************
*** 173,177 ****
MOV SI,ES
CMP SI,HeapPtr.w2
! JE @@6
CMP DX,ES:[DI].mSize.w2
JA @@2
--- 206,216 ----
MOV SI,ES
CMP SI,HeapPtr.w2
!
! ;; memchecker changed jump, else out of range
! ;; JE @@6
! jne @@m3
! jmp short @@6
! @@m3:
!
CMP DX,ES:[DI].mSize.w2
JA @@2
***************
*** 213,216 ****
--- 252,261 ----
POP DX
CLC
+
+ ;; memchecker code
+ jc @@NoCheck1 ; if error don't check
+ call MemCheckAddPtr
+ @@NoCheck1:
+
@@5: RET
@@9: XOR AX,AX
***************
*** 240,243 ****
--- 285,294 ----
POP AX
POP DX
+
+ ;; memchecker code
+ jc @@NoCheck2 ; if error don't check
+ call MemCheckAddPtr
+ @@NoCheck2:
+
CLC
RET
***************
*** 245,253 ****
CALL HeapError
CMP AL,1
! JB @@5
! JE @@9
MOV AX,AllocSize
JMP @@1
; Dispose memory
; In AX = Size
--- 296,353 ----
CALL HeapError
CMP AL,1
! JB @@5
! JE @@9
MOV AX,AllocSize
JMP @@1
+ ;;memchecker code
+ MemCheckAddPtr:
+ cmp CheckMem,0 ; if MemCheck disabled
+ je @@NoCheck ; don't check
+ mov cx,MemSize
+ jcxz @@NoCheck ; if size = 0, don't check
+ cmp dx,0 ; check if returned pointer is nil
+ jne @@no_error
+ cmp ax,0
+ je @@NoCheck ; don't check
+
+ @@no_error:
+ cmp cx,65520 ; is there room for upper memory check?
+ ja @@StorePointer2
+ mov si,ax ; save ax
+ mov es,dx
+ mov di,ax
+ add di,cx
+ cmp cx,65512
+ ja @@m22
+ add di,8 ; correct if we have a lower memory also
+ @@m22: mov ax,0cccch ; fill last 8 bytes with 0CCh
+ mov cx,4
+ cld
+ rep stosw
+ mov ax,si ; restore ax
+ mov cx,MemSize
+
+ cmp cx,65512 ; is there room for lower memory check?
+ ja @@StorePointer2
+ mov es,dx
+ mov di,ax
+ mov ax,0cccch ; fill first 8 bytes with 0CCh
+ mov cx,4
+ cld
+ rep stosw
+ mov ax,di ; first 8 bytes are skipped
+
+ @@StorePointer2:
+ push dx ; push ptr
+ push ax
+ push [MemSize] ; else push size
+ call dword ptr [StoreAlloc]
+
+ @@NoCheck:
+ ret
+
+
+
; Dispose memory
; In AX = Size
***************
*** 257,260 ****
--- 357,385 ----
DisMemory:
+ ;; memchecker code
+ cmp CheckMem,0
+ je @@DisMemoryStart
+ or ax,ax ; if Size = 0
+ jne @@m1
+ jmp short @@4 ; then no check
+ @@m1:
+ push bx ; push ptr
+ push cx
+ push ax ; push size
+ call dword ptr [FreeAlloc]
+
+ ;; add the extra overflow memory area size
+ cmp ax,65512 ; 65536-8-16
+ ja @@UpperArea
+ add ax,16
+ sub cx,8
+ jmp short @@DisMemoryStart
+ @@UpperArea:
+ cmp ax,65520 ; 65536-8-8
+ ja @@DisMemoryStart
+ add ax,8
+
+ @@DisMemoryStart:
+
OR AX,AX
JE @@6
***************
*** 367,370 ****
--- 492,496 ----
AND AX,8
RET
+
CODE ENDS